package test.resource

import graphql.schema.DataFetchingEnvironment
import io.vertx.core.Future
import io.vertx.core.json.JsonObject
import io.vertx.ext.web.RoutingContext
import io.vertx.kotlin.core.json.json
import io.vertx.kotlin.core.json.obj
import kotlinx.coroutines.reactor.flux
import kotlinx.coroutines.reactor.mono
import org.eclipse.microprofile.graphql.GraphQLApi
import org.eclipse.microprofile.graphql.Query

@GraphQLApi
class QueryResource {
  val jsonObject by lazy { json { obj("id" to "id", "name" to "name") } }

  @Query fun JsonObject() = jsonObject

  @Query fun JsonObjectFuture(): Future<JsonObject> = Future.succeededFuture(jsonObject)

  @Query fun JsonObjectMono() = mono { jsonObject }

  @Query
  fun JsonObjectFlux(rc: RoutingContext, env: DataFetchingEnvironment) = flux {
    send(jsonObject)
    send(jsonObject)
  }
}
